package cn.edu.cdu;

/**
 *
 */

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Welcome extends JPanel implements ActionListener{
    private JButton createGame,joinGame,exit;
    private JLabel name;
    private JLabel version;
    private JLabel prompt;
    private JLabel ip;


    public Welcome(JButton createGame,JButton joinGame ) {
        setVisible(true);
        setLayout(null);
        setBounds(0,0,800,700);
        //创建游戏按钮
        this.createGame=createGame;
        this.createGame.setBounds(340,350,120,40);
        this.createGame.setFont(new Font("微软雅黑",1,17));
        this.createGame.setForeground(new Color(42, 167, 194));
        this.createGame.setBackground(new Color(74, 69, 69));
        this.createGame.setFocusPainted(false);
        //加入游戏按钮
        this.joinGame=joinGame;
        this.joinGame.setBounds(340,420,120,40);
        this.joinGame.setFont(new Font("微软雅黑",1,17));
        this.joinGame.setForeground(new Color(42, 167, 194));
        this.joinGame.setBackground(new Color(74, 69, 69));
        this.joinGame.setFocusPainted(false);
        //标题
        this.name=new JLabel("五子棋游戏");
        this.name.setBounds(275,100,300,60);
        this.name.setFont(new Font("楷体",1,50));
        //版本
        this.version=new JLabel("联网版1.0");
        this.version.setBounds(500,170,100,30);
        this.version.setFont(new Font("楷体",1,20));
        this.version.setForeground(new Color(194, 124, 48));
        //退出游戏
        this.exit=new JButton("退出游戏");
        this.exit.setBounds(340,490,120,40);
        this.exit.setFont(new Font("微软雅黑",1,17));
        this.exit.setForeground(new Color(42, 167, 194));
        this.exit.setBackground(new Color(74, 69, 69));
        this.exit.setFocusPainted(false);
        this.exit.addActionListener(this);
        //创建房间提示
        this.prompt=new JLabel("房间已创建，正在等待加入...");
        this.prompt.setBounds(510,570,300,25);
        this.prompt.setFont(new Font("微软雅黑",1,18));
        this.prompt.setForeground(Color.RED);
        this.prompt.setVisible(false);
        //Ip提示
        this.ip=new JLabel("本房间地址为127.0.0.1");
        this.ip.setBounds(510,595,300,25);
        this.ip.setFont(new Font("微软雅黑",1,18));
        this.ip.setForeground(Color.RED);
        this.ip.setVisible(false);
        //加入布局
        this.add(createGame);
        this.add(joinGame);
        this.add(name);
        this.add(version);
        this.add(exit);
        this.add(prompt);
        this.add(ip);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==exit){
            System.exit(0);
        }
    }

    public void setIpAdress(String ip) {
        this.ip.setText("本房间的地址为"+ip);
    }

    public JLabel getPrompt() {
        return prompt;
    }

    public JLabel getIp() {
        return ip;
    }
}
